package com.pervasive.geoTagging;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class SaveActivity extends Activity{
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.save_layout);
		
		Intent i = getIntent();
		final String uri = i.getStringExtra("uri");
		if(uri == null){
			Toast.makeText(this, "no image", Toast.LENGTH_SHORT).show();
		}else{
			Drawable d = Drawable.createFromPath(uri);
			ImageView view = (ImageView) findViewById(R.id.imageView);
			view.setImageDrawable(d);
		}
		Button save = (Button) findViewById(R.id.save);
		save.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				Intent i = new Intent(getApplicationContext(), NoteActivity.class);
				i.putExtra("Codice", 1);
				startActivityForResult(i, 2);
			}
		});
		Button delete = (Button) findViewById(R.id.delete);
		delete.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				setResult(Activity.RESULT_CANCELED, null);
				finish();
			}
		});
	}

	public void onBackPressed() {
		super.onBackPressed();
		setResult(Activity.RESULT_CANCELED, null);
		finish();
	}
	
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(requestCode == 2 && resultCode == Activity.RESULT_OK){
				String note = data.getExtras().getString("Note");
				Intent i = new Intent(SaveActivity.this, CustomCameraActivity.class);
				i.putExtra("Note", note);
				setResult(Activity.RESULT_OK, i);
				finish();
		}
	}
	
}
